<?php
include "connect.php";
session_start();
$user=$_SESSION['user'];
$selectuser="SELECT * from b_users a, b_templates b where b.templateid=a.templateclass and a.username='$user'";
$selectuser2=mysql_query($selectuser);
$selectuser3=mysql_fetch_array($selectuser2);
print "<link rel='stylesheet' href='style.css' type='text/css'>";

if ($selectuser3[status]>="3")
   {
      print "<br><br><br><br><table border='0'>";
      print "<tr><td valign='top'><center>";
      print "<table width='70%' border='0' class='maintable'>";
      print "<tr class='headline'><td width='300px'>Admin Options";
      print "</td></tr>";
      print "<tr class='forumrow'><td>";
      include "adminleft.php";
      print "</td></tr></table></center></td>";
      print "<td valign='top' width='75%'><p align='left'>";
      print "<table width='90%' border='0' class='maintable'>";
      print "<tr class='headline'><td>Server Database Query Window";
      print "</td></tr>";
      print "<tr class='forumrow'><td>";
      if(isset($_POST['submit']))
      {
	     if ($_POST['db']=="1") {$db="$commondb";}
		 else if ($_POST['db']=="2") {$db="$chardb";}
		    else if ($_POST['db']=="3") {$db="$wowdb" ;}
		 if ($_POST['no3']=="")
	     {$comm="SELECT ".$_POST['no1']." FROM ".$_POST['no2'].$_POST['no4'].$_POST['no5'];}
		 else {
         $comm="SELECT ".$_POST['no1']." FROM ".$_POST['no2']." WHERE ".$_POST['no3'].$_POST['no4'].$_POST['no5'];}
         print "<br>$comm<br><br>";
         $a=mysql_query($comm) or die("There is error in your syntax, go back and check your command.");
		 $cnt = mysql_num_fields($a);
		 print "There is $cnt columns in this query, showing first 20.";
		 print "<table width='100%' border='1' cellspacing='0' cellpadding='2' style='color:white; font-size:11px'>";
		 while ($a2=mysql_fetch_array($a)) {
		 print "<tr>";
		    print "<td>$a2[0]</td>";
			print "<td class='catline2'>$a2[1]</td>";
			print "<td>$a2[2]</td>";
			print "<td class='catline2'>$a2[3]</td>";
			print "<td>$a2[4]</td>";
			print "<td class='catline2'>$a2[5]</td>";
			print "<td>$a2[6]</td>";
			print "<td class='catline2'>$a2[7]</td>";
			print "<td>$a2[8]</td>";
			print "<td class='catline2'>$a2[9]</td>";
			print "<td>$a2[10]</td>";
			print "<td class='catline2'>$a2[11]</td>";
			print "<td>$a2[12]</td>";
			print "<td class='catline2'>$a2[13]</td>";
			print "<td>$a2[14]</td>";
			print "<td class='catline2'>$a2[15]</td>";
			print "<td>$a2[16]</td>";
			print "<td class='catline2'>$a2[17]</td>";
			print "<td>$a2[18]</td>";
			print "<td class='catline2'>$a2[19]</td>";
			print "<td>$a2[20]</td>";
         print "</tr>";
		 }
      print "</table>";
      }
      else
      {
         print "Query sql command:<br><br>";
         print "<form action='query.php' method='post'>";
        
         //print "<textarea type='text' name='comm' cols='50' rows='10'></textarea><br>";
		 print "<font color='white'>SELECT <input name='no1' type='text' value='*' style='text-align:center' /> FROM <input name='no2' type='text'  style='text-align:center' />";
		 print "<br>[WHERE <input name='no3' type='text' style='text-align:center;width:328px'  />]<br><input name='no4' type='text' style='text-align:center;width:385px'/><br>";
		 print " LIMIT <select name='no5'>";
		 print "<option value=''>No limit</option><option value='10'>10</option>";
		 print "<option value=' LIMIT 100' selected='selected'>100</option>";
		 print "<option value=' LIMIT 500'>500</option><option value=' LIMIT 1000'>1000</option></select>";
		 print "<br><br><font size='1'>Example: SELECT name FROM characters WHERE level<=25 ORDER BY level ASC LIMIT 10</font></font><br><br>";
		 print "<label><input name='db' type='radio' value='1' />Forum DB ($commondb) |</label>";
		 print "<label><input name='db' type='radio' value='2' />Character DB ($chardb) |</label>";
		 print "<label><input name='db' type='radio' value='3' checked />World DB ($wowdb)</label> <br><br>";
         print "<label><input type='submit' name='submit' value='QUERY'></form>";
   
      }
      print "</td></tr></table>";
   }
   
else
   {
     print "<table width='70%' border='0'>";
     print "<tr class='headline'><td><center>Not logged in as Admin</td></tr>";
     print "<tr class='forumrow'><td>";
     print "You are not logged in as Administrator, please log in.";
     print "<form method='POST' action='../authenticate.php'>";
     print "Type Username Here: <input type='text' name='username' size='15'><br>";
     print "Type Password Here: <input type='password' name='password' size='15'><br>";
     print "<input type='submit' value='submit' name='submit'>";
     print "</form>";
     print "</td></tr></table>";
   }

?>

